import 'package:flutter_shark_im/entity/message/common_response_entity.dart';
import 'package:flutter_shark_im/entity/message/send_entity.dart';
import 'package:flutter_shark_im/entity/message/user_list_response_entity.dart';
import 'package:flutter_shark_im/entity_factory.dart';
import 'authentication_entity.dart';
import 'authentication_response_entity.dart';
import 'receive_entity.dart';

class BaseMessageEntity {
	int no;
	String createTime;
	int id;

	BaseMessageEntity({this.no, this.createTime, this.id});

	BaseMessageEntity.fromJson(Map<String, dynamic> json) {
		no = json['no'];
		createTime = json['createTime'];
		id = json['id'];
	}

	Map<String, dynamic> toJson() {
		final Map<String, dynamic> data = new Map<String, dynamic>();
		data['no'] = this.no;
		data['createTime'] = this.createTime;
		data['id'] = this.id;
		return data;
	}
	
	 static dynamic convertEntity(Map<String, dynamic> json) {
		int id = json['id'];
		switch(id) {
			case HEART_BEAT:
				return EntityFactory.generateOBJ<HeartBeatEntity>(json);
			case COMMON_RESPONSE:
				return EntityFactory.generateOBJ<CommonResponseEntity>(json);
			case AUTHENTICATION:
				return EntityFactory.generateOBJ<AuthenticationEntity>(json);
			case AUTHENTICATION_RESPONSE:
				return EntityFactory.generateOBJ<AuthenticationResponseEntity>(json);
			case GET_USER_LIST:
				return EntityFactory.generateOBJ<GetUserListEntity>(json);
			case SEND_MESSAGE:
				return EntityFactory.generateOBJ<SendEntity>(json);
			case RECEIVE_MESSAGE:
				return EntityFactory.generateOBJ<ReceiveEntity>(json);
			case GET_USER_LIST_RESPONSE:
				return EntityFactory.generateOBJ<UserListResponseEntity>(json);
			default:
				return null;
		}
	}

	// 心跳
	static const HEART_BEAT = 0x0;
	// 通用回复
	static const COMMON_RESPONSE = 0x100;
	// 鉴权
	static const AUTHENTICATION = 0x1;
	// 鉴权回复
	static const AUTHENTICATION_RESPONSE = 0x101;
	// 获取联系人列表
	static const GET_USER_LIST = 0x2;
	// 获取联系人列表回复
	static const GET_USER_LIST_RESPONSE = 0X102;
	// 发送消息
	static const SEND_MESSAGE = 0x3;
	// 接收消息
	static const RECEIVE_MESSAGE = 0x4;
}

class HeartBeatEntity extends BaseMessageEntity {



	HeartBeatEntity.fromJson(Map<String, dynamic> json) {
		no = json['no'];
		createTime = json['createTime'];
		id = json['id'];
	}

	HeartBeatEntity() : super(id: BaseMessageEntity.HEART_BEAT);
}

class GetUserListEntity extends BaseMessageEntity {



	GetUserListEntity.fromJson(Map<String, dynamic> json) {
		no = json['no'];
		createTime = json['createTime'];
		id = json['id'];
	}

	GetUserListEntity() : super(id: BaseMessageEntity.GET_USER_LIST);
}

class Message {

	bool isMe;

	String content;

	DateTime time;

	Message({this.isMe: true, this.content, this.time});

	@override
	String toString() {
		return 'Message{isMe: $isMe, content: $content, time: $time}';
	}


}